package net.onceface.application.assembler;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import net.onceface.application.dto.CategoryDTO;
import net.onceface.core.domain.Category;

public class CategoryAssembler {

	public static CategoryDTO toDTO(Category category){
		if(category == null){
			return null;
		}
		CategoryDTO result = new CategoryDTO();
		result.setCode(category.getCode());
		result.setId(category.getId());
		result.setLeve(category.getLeve());
		result.setName(category.getName());
		result.setParent(toDTO(category.getParent()));
		result.setParentId(category.getParentId());
		result.setPicture(category.getPicture());
		result.setRemark(category.getRemark());
		result.setSortOrder(category.getSortOrder());
		result.setVersion(category.getVersion());
		result.setLeve(category.getLeve());
		return result;
	}
	
	public static Category toEntity(CategoryDTO category){
		if(category == null){
			return null;
		}
		Category result = new Category();
		result.setCode(category.getCode());
		result.setId(category.getId());
		result.setLeve(category.getLeve());
		result.setName(category.getName());
		result.setParent(toEntity(category.getParent()));
		result.setParentId(category.getParentId());
		result.setPicture(category.getPicture());
		result.setRemark(category.getRemark());
		result.setSortOrder(category.getSortOrder());
		result.setVersion(category.getVersion());
		result.setLeve(category.getLeve());
		return result;
	}
	
	public static List<Category>  toEntities(Collection<CategoryDTO>  categorys){
		if (categorys == null) {
			return null;
		}
		List<Category> results = new ArrayList<Category>();
		for (CategoryDTO each : categorys) {
			results.add(toEntity(each));
		}
		return results;
	}
	
	public static List<CategoryDTO>  toDTOs(Collection<Category>  categorys){
		if (categorys == null) {
			return null;
		}
		List<CategoryDTO> results = new ArrayList<CategoryDTO>();
		for (Category each : categorys) {
			results.add(toDTO(each));
		}
		return results;
	}
}
